package com.google.code.bankagregator.adapter.bank.forum;

import com.google.code.bankagregator.adapter.Adapter;
import com.google.code.bankagregator.adapter.bank.forum.parser.credit.ForumAutoCreditParser;
import com.google.code.bankagregator.adapter.bank.forum.parser.credit.ForumRealtyCreditParser;
import com.google.code.bankagregator.adapter.bank.forum.parser.deposit.ForumDepDecadeParser;
import com.google.code.bankagregator.adapter.bank.forum.parser.deposit.ForumDepFreeParser;
import com.google.code.bankagregator.adapter.bank.forum.parser.deposit.ForumDepToAdulthoodParser;
import com.google.code.bankagregator.adapter.exception.AdapterConnectException;
import com.google.code.bankagregator.entities.Credit;
import com.google.code.bankagregator.entities.Deposit;
import com.google.code.bankagregator.vo.AdapterResult;
import com.google.code.bankagregator.vo.AdapterWarning;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kirill
 * Date: 15.06.13
 * Time: 1:34
 * To change this template use File | Settings | File Templates.
 */
public class AdapterForum implements Adapter {
    @Override
    public AdapterResult getResult() {
        AdapterResult result = new AdapterResult();

        List<Credit> credits = new ArrayList<Credit>();
        List<Deposit> deposits = new ArrayList<Deposit>();
        List<AdapterWarning> warnings = new ArrayList<AdapterWarning>();


        List<Credit> creditList = null;
        List<Deposit> depositList = null;
        try {
            creditList = new ForumAutoCreditParser().getCredit();
            credits.addAll(creditList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            creditList = new ForumRealtyCreditParser().getCredit();
            credits.addAll(creditList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }


        try {
            depositList = new ForumDepFreeParser().getEURDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepFreeParser().getUAHDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepFreeParser().getUSDDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }


        try {
            depositList = new ForumDepDecadeParser().getEURDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepDecadeParser().getUAHDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepDecadeParser().getUSDDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }


        try {
            depositList = new ForumDepToAdulthoodParser().getUAHDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepToAdulthoodParser().getUSDDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ForumDepToAdulthoodParser().getEURDeposit();
            deposits.addAll(depositList);
        } catch (AdapterConnectException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }

        result.setCredits(credits);
        result.setDeposits(deposits);
        result.setWarnings(warnings);
        return result;
    }
}
